package com.tianji.learning.controller;


import com.tianji.api.dto.leanring.LearningLessonDTO;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author hc
 * @since 2024-08-20
 */
@Api(tags = "我的课程相关接口")
@RestController
@RequestMapping("/lessons")
public class LearningLessonController {

    @Autowired
    private ILearningLessonService lessonService;

    @GetMapping("page")
    @ApiOperation("分页查询我的课程")
    public PageDTO<LearningLessonVO> pageQueryMyLessons(PageQuery pageQuery){
        return lessonService.pageQueryMyLessons(pageQuery);
    }

    @GetMapping("now")
    @ApiOperation("查询正在学习的课程")
    public LearningLessonVO queryMyNowStudy(){
         return lessonService.queryMyNowStudy();
    }

    @GetMapping("{courseId}")
    @ApiOperation(value = "查询用户课表中指定课程状态")
    public LearningLessonVO queryLessonStatus(@PathVariable Long courseId){
        return lessonService.queryLessonStatus(courseId);
    }

    /**
     * 校验当前用户是否可以学习当前课程
     * @param courseId 课程id
     * @return true：课程有效，false：课程无效，不能学习
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("校验当前用户是否可以学习当前课程")
    public Long isLessonValid(@PathVariable("courseId") Long courseId){
        return lessonService.isLessonValid(courseId);
    }

    /**
     * 统计课程学习人数
     * @param courseId 课程id
     * @return 学习人数
     */
    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程学习人数")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return lessonService.countLearningLessonByCourse(courseId);
    }

    @DeleteMapping("/{courseId}")
    @ApiOperation("用户删除课程")
    public void deleteLesson(@PathVariable Long courseId){
        lessonService.deleteLesson(courseId);
    }

    @PostMapping("plans")
    @ApiOperation("创建学习计划")
    public void addLearningPlan(@RequestBody LearningPlanDTO planDTO){
        lessonService.addLearningPlan(planDTO);
    }

    @GetMapping("plans")
    @ApiOperation("查询学习计划进度")
    public LearningPlanPageVO pageQueryLearningPlan(PageQuery pageQuery){
        return lessonService.pageQueryLearningPlan(pageQuery);

    }

}
